import { Route, Redirect } from 'react-router-dom'
import { isAuth } from '../../utils/auto'

const AutoRoute = ({ component: Component, path, ...rest }) => {
  return (
    <Route
      {...rest}
      path={path}
      render={(props) => {
        if (isAuth()) {
          return <Component {...props} />
        } else {
          return (
            <Redirect
              to={{
                pathname: '/login',
                formPath: path,
              }}
            />
          )
        }
      }}
    ></Route>
  )
}

export default AutoRoute
